/******************************************************************************
Copyright:
2009 Jens Collin (jens.collin@dinomin.com)

This file is part of Envox Decompiler.

Envox Decompiler is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Envox Decompiler is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with KitchenOS.  If not, see <http://www.gnu.org/licenses/>.

******************************************************************************/
using System;

namespace EnvoxDecompiler
{
	/// <summary>
	/// Summary description for Variable.
	/// </summary>
	public class Variable
	{

		public enum TYPE
		{
			var_integer = 1,
			var_unknown, /* could be the old string type */
			var_string,
			var_date,
			var_time,
			var_binary
		}

		public enum SHARE_MODE
		{
			not_shared = 0,
			node_shared,
			channel_shared,
			group_shared
		}

		private string _name;
		private TYPE _type;
		private int _arraySize;
		private SHARE_MODE _shareMode;

		public Variable(string name, TYPE type, int arraySize, SHARE_MODE shareMode)
		{
			_name = name;
			_type = type;
			_arraySize = arraySize;
			_shareMode = shareMode;
		}


		public void Trace()
		{
			EnvoxDecompiler.Trace.Info("Variable: " + _name + " TYPE: "+_type.ToString() + 
				" size: " + _arraySize + " SHARE_MODE: " + _shareMode.ToString());
		}

		public string GetName()
		{
			return _name;
		}

		/// <summary>
		/// Get type of variable that this is.
		/// </summary>
		/// <returns>int representation of var type.</returns>
		public int GetVarType()
		{
			return (int)_type;
		}

		public int GetArraySize()
		{
			return _arraySize;
		}

		/// <summary>
		/// Studio has the attributes on a variable in a bitted into a variable.
		/// Figure out the layout for this var and return the mask.
		/// </summary>
		/// <returns></returns>
		public int GetAttribute()
		{
			int ret = 0;
			if (_shareMode == SHARE_MODE.node_shared)
			{
				ret |= 8;
			}
			else if (_shareMode == SHARE_MODE.channel_shared)
			{
				ret |= 32;
			}
			else if (_shareMode == SHARE_MODE.group_shared)
			{
				ret |= 64;
			}

			if (_arraySize != 0)
			{
				ret |= 16;
			}
			return ret;
		}

	}
}
